/*=========================================================================
 Copyright (c) 2008, Nokia Corporation and/or its subsidiary(-ies).
 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
 
     * Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.
     * Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.
     * Neither the name of the Nokia Corporation and/or its subsidiary(-ies)nor the
       names of its contributors may be used to endorse or promote products
       derived from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 
 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================================*/
#ifndef ncvImageOperations_H
#define ncvImageOperations_H
#include "ncvImage.h"
#include "ncvRotationOp.h"
#include "ncvResizeOp.h"
#include "ncvShearOp.h"
#include "ncvArithmeticOp.h"
#include "ncvWarpOp.h"
#include "ncvColorConversionOp.h"
#include "ncvThresholdOp.h"
#include "ncvComparisonOp.h"
#include "ncvConvolutionOp.h"
#include "ncvMedianfilterOp.h"
#include "ncvGaussianSmoothOp.h"
#include "ncvTemplatematchOp.h"
#include "ncvCornerDetectionOp.h"
#include "ncvMatrix.h"
#include "ncvEdgeDetectionOp.h"
#include "ncvMorphologicalOp.h"

/**
 * \class CImageOperations
 * \brief CImageOperations provides an simplified access to image operations.
 * Each operation is a static method that creates and returns the result bitmap.
 * \note The usage pattern id different from the image operation classes 
 * \note The resulting bitmap will be the same TDisplayMode as the source.
 * 
 * Usage
 * <pre>
 * ...
 * CNokiaCVImage* iTarget = CImageOperations::Rotate(iSource, 45);
 * ...
 * delete iTarget;
 * 
 * </pre>
 */
class CImageOperations : public CBase
	{
public:

	/**
	 * \brief Resizes the source image. See CResizeOp for more information
	 * \param aSource Source image.
	 * \param aSize size of the new bitmap
	 * \param aBilinear Use bilinear resize (slower) or normal.
	 * \note the function can leave
	 * \return resulting resized bitmap
	 */
	IMPORT_C  static void Resize(CNokiaCVImage* aSource, CNokiaCVImage* aTarget, TBool aBilinear);

	/**
	 * \brief Rotates the source image. See CRotationOp for more information
	 * \param aSource Source image.
	 * \param aAngle Angle (90 for right angle) of rotation in degrees.
	 * \note the function can leave
	 * \return resulting rotated bitmap
	 */
	IMPORT_C  static void Rotate(CNokiaCVImage* aSource, CNokiaCVImage* aTarget, TInt aAngle);

	/**
	 * \brief Shear operation for CNokiaCVImages
	 * \param aImage Source image.
	 * \param aAngle Angle (in degrees) to shear the image.
	 * \param aDirection Direction to shear the image
	 * \note the function can leave
	 * \return resulting sheared bitmap
	 */
	IMPORT_C  static void Shear(CNokiaCVImage* aSource, CNokiaCVImage* aTarget, TInt aAngle, TDirection aDirection);
	
	IMPORT_C static void ArithmeticOp(CNokiaCVImage* aSource1, CNokiaCVImage* aSource2, CNokiaCVImage* aTarget, CArithmeticOp::TArithmeticOperationType aOperation, TBool aAbsolute, TBool aClipColors);

	/**
	 * \brief Warps the source image and creates a result bitmap. See CWarpOp for more information
	 * \param aSource Source image.
	 * \param aSourcePoint Source point to start the warp from.
	 * \param aDestinationPoint Destination point to warp towards.
	 * \note the function can leave	 
	 * \return warped result bitmap
	 */
	IMPORT_C static void Warp(CNokiaCVImage* aSource, CNokiaCVImage* aTarget, TPoint aSourcePoint, TPoint aDestinationPoint);

	/**
	 * \brief Converts the source image to another TDisplayMode.
	 * \param aImage Source image.
	 * \param aTargetMode TDisplayMode of the resulting bitmap
	 * \note the function can leave
 	 * \return bitmap in target TDisplayMode
	 */
	IMPORT_C static void ColorConversion(CNokiaCVImage* aSource, CNokiaCVImage* aTarget, TDisplayMode aTargetMode);

	/**
	 * \brief Thresholding operation creates an black and white bitmap from the source, See CThresholdOp for more information.
	 * \param aImage Source image.
	 * \param aThreshold an integer value (0-255) to use as a threshold.
	 * \param aAdaptive use simple static thresholding or adaptive
	 * \param aSize aSize x aSize neighborhood to use for adaptation. Only applicable for  adaptive thresholding
	 * \param aConstant constant value that is subtracted from the mean. Only applicable for  adaptive thresholding
	 * \note the function can leave
	 * \return result black and white bitmap
	 */
	IMPORT_C static void Threshold(CNokiaCVImage* aSource, CNokiaCVImage* aTarget, TUint8 aThreshold, TBool aAdaptive, TInt aSize = 0, TInt aConstant = 0);

	/**
	 * \brief Pixel-wise image comparison operations: "greater than", "less than" and "equal". 
	 * Compares two source images using given operator and creates an black and white result bitmap.
	 * See CComparisonOp for more information.
	 * \param aSource1 first source image
	 * \param aSource2 second source image
	 * \param aOperation Comparison operation: .EGreater, ELess or EEqual
	 * \param aRect subregion of images 1 and 2 that are compared
	 * \note These two images must be of same TDisplayMode and same size
	 * \note the function can leave
	 * \return result black and white bitmap
	 */
	IMPORT_C static void Comparison(CNokiaCVImage* aSource1, CNokiaCVImage* aSource2, CNokiaCVImage* aTarget, CComparisonOp::TComparisonType aOperation, TRect aRect);

	/**
	 * \brief Performs convolution of CNokiaCVImage and a kernel (CNokiaCVMatrix). See CConvolutionOp for more information.
	 * \param aSource Source image.
	 * \param aKernel CNokiaCVMatrix Kernel to use for convolution. Only 3x3 and 5x5 matrices are supported.
	 * \param aNormFactor normalization factor. Typically equals to the sum of kernel values.
	 * Each resulting pixel value is divided by the normalisation factor.
	 * \note the function can leave
	 * \return result bitmap
	 */
	IMPORT_C static void Convolution(CNokiaCVImage* aSource, CNokiaCVImage* aTarget, CNokiaCVMatrix& aKernel, TInt aNormFactor);

	IMPORT_C static void EdgeDetect(CNokiaCVImage* aSource, CNokiaCVImage* aTarget, CEdgeDetectionOp::TEdgeDetectionMethod aMethod);

	/**
	 * \brief Median filter. See CMedianFilterOp for more info.
	 * \param aSource Source image.
	 * \param aRows size of the median filter kernel. Possible values are:
	 *	- 3 for 3x3
	 *	- 5 for 5x5
	 *	- 7 for 7x7
	 * \note the function can leave
	 * \return result bitmap
	 */
	IMPORT_C static void Median(CNokiaCVImage* aSource, CNokiaCVImage* aTarget,  TInt aRows);

	IMPORT_C static void Morph(CNokiaCVImage* aSource, CNokiaCVImage* aTarget, CMorphologicalOp::TMorphologicalOperation aOperation);

	/**
	 * \brief Gaussian smoothing filter
	 * \param aSource Source image.
	 * \param aSize size of the Gaussian kernel: 3 or 5
	 * \note the function can leave
	 * \return result bitmap
	 */
	IMPORT_C static void Gaussian(CNokiaCVImage* aSource, CNokiaCVImage* aTarget, TUint aSize);

	/**
	 * \brief Moravec corner detection filter.
	 * \param aSource Source image.
	 * \param aNeighborhoodSize Size of the neighborhood to use for adaptive thresholding
	 * \param aConstant a constant value to subtract from the mean threshold
	 * \note the function can leave
	 * \return result bitmap
	 */
	IMPORT_C static void Moravec(CNokiaCVImage* aSource, CNokiaCVImage* aTarget, TInt aNeighborhoodSize = 20, TInt aConstant = 25);

	/**
	 * \brief Crops the given image to given size.
	 * \param aSource Source image.
	 * \param aTl Top-left corner of the crop rectangle 
	 * \param aBr Bottom-right corner of the crop rectangle 
	 * \note the function can leave
	 * \return result bitmap
	 */
	IMPORT_C static void Crop(CNokiaCVImage* aSource, CNokiaCVImage* aTarget, TPoint aTl, TPoint aBr);

	/**
	 * \brief Template matching operation for two CNokiaCVImages. See CTemplateMatchOp for more info.
	 * \param aImage Source image.
	 * \param aTemplate CNokiaCVImage containing the template to match
	 * \note the function can leave
	 * \return the position of the best match.
	 */
	IMPORT_C static TPoint TemplateMatch(CNokiaCVImage* aImage, CNokiaCVImage* aTemplate);

	/**
	 * \brief Template matching / cross correlation operation for two CNokiaCVImages. See CTemplateMatchOp for more info.
	 * \param aImage Source image.
	 * \param aTemplate CNokiaCVImage containing the template to match
	 * \note the function can leave
	 * \return grey scale image of the cross correlation values
	 */
	IMPORT_C static void CrossCorrelation(CNokiaCVImage* aImage,  CNokiaCVImage* aTarget, CNokiaCVImage* aTemplate);

	/**
	 * \brief Convert image from RGB to another colorspace (e.g. HSV, LAB, XYZ)
	 * \param aImage Image to convert
	 * \param aColorspace Colorspace to convert to. Possible values EColorSpaceRgb,
	 * EColorSpaceYuv,
	 * EColorSpaceHsv,
	 * EColorSpaceLab,
	 * EColorSpaceLAlphaBeta,
	 * EColorSpaceLms,
	 * EColorSpaceXyz
	 *
	 * \note Notice that after conversion the images pixel data is in another colorspace and
	 * you may not be able to draw the image on the screen.
	 *
	 * \return bitmap in given colorspace
	 */
	IMPORT_C static void ConvertToColorSpace(CNokiaCVImage* aImage, CNokiaCVImage* aTarget, TColorSpace aColorspace);

private:


};

#endif
